/**
 * Created by DELL on 2017/3/20.
 */
(function() {
    'use strict';
    var checkedObject = {};
    /**
     * 中介联系人 列表初始化设置
     * @type {Object}
     */
    var settings = {
        "sAjaxSource": window.globalHost + common.agentListPort,
        "aoColumns": [
            {
                "mDataProp": function (obj) {
                    return obj.agentName===""?"无姓名":obj.agentName;
                },
                "sTitle": "姓名",
                "sDefaultContent": ""
            }, {
                "mDataProp": function(obj) {
                    return obj.mobile===""?"无信息":obj.mobile;
                },
                "sTitle": "手机号码",
                "sDefaultContent": ""
            }, {
                "mDataProp": function (obj) {
                    return obj.companyName===""?"无信息":obj.companyName;
                },
                "sTitle": "所属公司",
                "sDefaultContent": ""
            }, {
                "mDataProp": function (obj) {
                    return obj.storeName===""?"无信息":obj.storeName;
                },
                "sTitle": "所属门店",
                "sDefaultContent": ""
            }, {
                "mDataProp": function (obj) {
                    return obj.authTime===""?"无信息":obj.authTime===undefined?"undefined":obj.authTime;
                },
                "sTitle": "审核时间",
                "sDefaultContent": ""
            }, {
                "mDataProp": function (obj) {
                    return '<button type="button" class="btn btn-success btn-xs btn-block show-info" data-id="' + obj.id + '">查看详情</button>';
                },
                "sTitle": "操作",
                "sDefaultContent": ""
            }
            // , {
            //     "mDataProp": function (obj) {
            //         return '<button type="button" class="btn btn-success btn-xs btn-block update-remark" data-id="' + obj.id + '">修改备注</button>';
            //     },
            //     "sTitle": "操作",
            //     "sDefaultContent": ""
            // }
        ],
        "fnServerParams": function(aoData) {
            return common.getSearchData("form.data-list-search",aoData);
        }
    };
    var options = $.extend(true, {}, _dataTableSettings, settings);
    /**
     * 实例化 中介联系人 列表插件
     * @type {[type]}
     */
    var $currentDataTable=$("#data-list");
    var oTable = $currentDataTable.dataTable(options);
    searchList.getDataList(oTable);
    searchList.resetSearch(oTable);
    /**
     * 绑定数据列表中的多选框
     * @param  {[type]} ev){                     var checkItem [description]
     * @return {[type]}       [description]
     */
    $currentDataTable.on("change", ".checkbox", function(ev) {
        var checkItem = $(this).find("input[type='checkbox']");
        var checkId = checkItem[0].id.replace('checkbox-', '');
        var checkName=checkItem.attr("data-name");
        if (checkItem[0].checked) {
            checkedObject[checkId] = {
                id:checkId,
                name:checkName
            };
        } else {
            delete checkedObject[checkId];
        }
        ev.stopPropagation();
    });

    $currentDataTable.off("click").on("click",".show-info",function (ev) {
        var $this=$(this);
        var selfId=$this.attr("data-id");
        common.openInsertDialog({
            title:'注册信息详情',
            url:"./loginManage/dataInfo.html?agentId="+selfId,
            btn:[],
            // 'sAjaxSource': window.globalHost + common.agentUpdatePort,
            'area': ['1000px', '600px'],
            ok: function() {
                //  新增信息成功之后，刷新列表页面
                // oTable.fnClearTable();
            },
            cancel: function() {}
        });
        ev.stopPropagation();
    });

}).call(this);